﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using AspNetCs.Model;
using AspNetCs.IDAL;

namespace AspNetCs.SQLServerDAL
{
    public class AncestralHallBBS_DAL:IAncestralHallBBS
    {
        /// <summary>
        /// 添加宗祠论坛
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(AncestralHallBBS_Model model)
        {
            int count = 0;
            db.ParameterArry[] paras=new db.ParameterArry[7];

            paras[0].dbType=SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = model.AncestralHallId;

            paras[1].dbType=SqlDbType.Text;
            paras[1].parName="@BBSTop";
            paras[1].objValue=model.BBSTop;

            paras[2].dbType=SqlDbType.Text;
            paras[2].parName="@BBSBottom";
            paras[2].objValue=model.BBSBottom;

            paras[3].dbType=SqlDbType.Text;
            paras[3].parName="@BBSAnnouce";
            paras[3].objValue=model.BBSAnnouce;

            paras[4].dbType=SqlDbType.DateTime;
            paras[4].parName="@CreateTime";
            paras[4].objValue=model.CreateTime;

            paras[5].dbType=SqlDbType.Int;
            paras[5].parName="@IsCheck";
            paras[5].objValue=model.IsCheck;

            paras[6].dbType=SqlDbType.Int;
            paras[6].parName="@IsDel";
            paras[6].objValue=model.IsDel;

            string cmdText = "insert into AncestralHallBBS values ({0},{1},{2},{3},{4},{5},{6})";
            cmdText = string.Format(cmdText, paras[0].parName, paras[1].parName, paras[2].parName, paras[3].parName, paras[4].parName, paras[5].parName, paras[6].parName);
            db dbclass=new db();
            count = dbclass.ExcSql(cmdText,paras);
            return count;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public DataTable GetDataTable(string filter)
        {
            string cmdText = "select *from AncestralHallBBS where {0}";
            cmdText = string.Format(cmdText,filter);
            db dbclass = new db();
            
            DataTable dataTable = new DataTable();
            dataTable = dbclass.GetSql_DataTable(cmdText);
            return dataTable;
        }

        /// <summary>
        /// 修改宗祠论坛
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(AncestralHallBBS_Model model)
        {
            int count = 0;
            db.ParameterArry[] paras = new db.ParameterArry[8];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = model.AncestralHallId;

            paras[1].dbType = SqlDbType.Text;
            paras[1].parName = "@BBSTop";
            paras[1].objValue = model.BBSTop;

            paras[2].dbType = SqlDbType.Text;
            paras[2].parName = "@BBSBottom";
            paras[2].objValue = model.BBSBottom;

            paras[3].dbType = SqlDbType.Text;
            paras[3].parName = "@BBSAnnouce";
            paras[3].objValue = model.BBSAnnouce;

            paras[4].dbType = SqlDbType.DateTime;
            paras[4].parName = "@CreateTime";
            paras[4].objValue = model.CreateTime;

            paras[5].dbType = SqlDbType.Int;
            paras[5].parName = "@IsCheck";
            paras[5].objValue = model.IsCheck;

            paras[6].dbType = SqlDbType.Int;
            paras[6].parName = "@IsDel";
            paras[6].objValue = model.IsDel;


            paras[7].dbType = SqlDbType.Int;
            paras[7].parName = "@Id";
            paras[7].objValue = model.Id;

            string cmdText = "update  AncestralHallBBS set AncestralHallId={0},BBSTop={1},BBSBottom={2},BBSAnnouce={3},CreateTime={4},IsCheck={5},IsDel={6} where Id={7}";
            cmdText = string.Format(cmdText, paras[0].parName, paras[1].parName, paras[2].parName, paras[3].parName, paras[4].parName, paras[5].parName, paras[6].parName, paras[7].parName);
            db dbclass = new db();
            count = dbclass.ExcSql(cmdText);
            return count;
        }

        /// <summary>
        /// 删除宗祠论坛(物理删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            int count = 0;
            string cmdText = "delete from AncestralHallBBS where AncestralHallId=@AncestralHallId";
            db.ParameterArry[] paras = new db.ParameterArry[1];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = id;

            db dbclass = new db();

            count = dbclass.ExcSql(cmdText,paras);

            return count;
        }

        /// <summary>
        /// 删除宗祠论坛(逻辑删除)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Hidden(int id)
        {
            int count = 0;
            string cmdText = "update AncestralHallBBS set IsDel=1 where AncestralHallId=@AncestralHallId";
            db.ParameterArry[] paras = new db.ParameterArry[1];
            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = id;

            db dbclass = new db();

            count = dbclass.ExcSql(cmdText, paras);

            return count;
        }

        /// <summary>
        /// 通过宗祠编号查询宗祠论坛
        /// </summary>
        /// <param name="CreateId">宗祠编号</param>
        /// <param name="RequeryItems">查询的字段</param>
        /// <param name="IsDel">是否查询的被删除的信息 0:没有删除的 1:删除了的 2:所有的</param>
        /// <returns></returns>
        public DataTable getAncestralHallBBSByAncestralHallId(int id, string RequeryItems, int IsDel)
        {
            DataTable dataTable =new DataTable();
            db.ParameterArry[] paras = new db.ParameterArry[2];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = id;

            paras[1].dbType = SqlDbType.Int;
            paras[1].parName = "@IsDel";
            paras[1].objValue = IsDel;


            string cmdText = "select {0} from AncestralHallBBS where AncestralHallId=@AncestralHallId and IsDel=@IsDel";
            cmdText = string.Format(cmdText,RequeryItems);
            db dbclass = new db();

            dataTable = dbclass.GetSql_DataTable(cmdText,paras);
            return dataTable;
        }


        /// <summary>
        /// 修改宗祠论坛顶部
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateTopContent(AncestralHallBBS_Model model)
        {
            db.ParameterArry[] paras = new db.ParameterArry[2];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = model.AncestralHallId;

            paras[1].dbType = SqlDbType.Text;
            paras[1].parName = "@BBSTop";
            paras[1].objValue = model.BBSTop;

            string cmdText = "update AncestralHallBBS set BBSTop=@BBSTop where AncestralHallId=@AncestralHallId";

            db dbclass = new db();
            int count = dbclass.ExcSql(cmdText,paras);
            return count;

        }


        /// <summary>
        /// 修改宗祠论坛底部
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateBottomContent(AncestralHallBBS_Model model)
        {
            db.ParameterArry[] paras = new db.ParameterArry[2];

            paras[0].dbType = SqlDbType.Int;
            paras[0].parName = "@AncestralHallId";
            paras[0].objValue = model.AncestralHallId;

            paras[1].dbType = SqlDbType.Text;
            paras[1].parName = "@BBSBottom";
            paras[1].objValue = model.BBSBottom;

            string cmdText = "update AncestralHallBBS set BBSBottom=@BBSBottom where AncestralHallId=@AncestralHallId";

            db dbclass = new db();
            int count = dbclass.ExcSql(cmdText, paras);

            return count;
        }
    }
}
